import { HYEventStore } from 'hy-event-store'

import { getRankings } from '../service/api_music'

const rankingMap = {0:"newRanking", 1:"hotRanking", 2:"originRanking", 3:"upRanking"}
const rankingStore = new HYEventStore({
  state:{
    newRanking:{},     //0：新歌
    hotRanking:{},      //1：热歌     Ranking  排名
    originRanking:{},   //2：原创
   upRanking:{}       //3：飙升
  },
  actions:{
    getRankingDataAction(ctx){
     for( let i=0;i<4;i++){
      getRankings(i).then(res=>{
        const rankingName = rankingMap[i]
        ctx[rankingName] = res.playlist
        // switch(i){
        //   // 0：新歌榜   1：热歌榜   2：原创榜   3：飙升榜
        //   case 0:
        //     // console.log("新歌：",res);
        //     ctx.newRanking = res.playlist;
        //     break;
        //   case 1:
        //     // console.log("热歌：",res);
        //     ctx.hotRanking = res.playlist;
        //     break;
        //   case 2:
        //     // console.log("原创：",res);
        //     ctx.originRanking = res.playlist;
        //     break;
        //   case 3:
        //     // console.log("飙升：",res);
        //     ctx.upRanking = res.playlist;
        //     break;
        // }
      })
     }
    }
  }
})

export{
  rankingStore,
  rankingMap
}